001 /* EVolve - an Extensible Software Visualization Framework 002 * Copyright (C) 2001-2002 Qin Wang 003 * 004 * This library is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Library General Public 006 * License as published by the Free Software Foundation; either 007 * version 2 of the License, or (at your option) any later version. 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Library General Public License for more details. 013 * 014 * You should have received a copy of the GNU Library General Public 015 * License along with this library; if not, write to the 016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 017 * Boston, MA 02111-1307, USA. 018 */ 019 020 /* 021 * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/ 022 */ 023 024 package EVolve; 025 026 import EVolve.data.*; 027 import EVolve.visualization.*; 028 import EVolve.visualization.VizFactory.VisualizationFactory; 029 import EVolve.util.*; 030 import EVolve.util.settings.SceneSetting; 031 import EVolve.exceptions.DataProcessingException; 032 import EVolve.exceptions.CancelLoadDataException; 033 import EVolve.exceptions.EVolveException; 034 035 import java.awt.*; 036 import java.util.*; 037 import java.net.URL; 038 import javax.swing.*; 039 040 public class Scene { 041 public static final String VERSION = "EVolve 1.2.3"; 042 private static Scene e; 043 044 private DataSourceManager dsm; 045 private DataManager dm; 046 private VisualizationManager vm; 047 private UIManager um; 048 private ToolsManager tm; 049 private Filter filter; 050 private String autoDataFilename; 051 private String currentDataFilename; 052 private boolean dataLoaded; 053 054 private Scene() { 055 } 056 057 public static void start(ArrayList dsList, VisualizationFactory[] factory) { 058 e = new Scene(); 059 060 e.vm = new VisualizationManager(factory); 061 e.dsm = new DataSourceManager(dsList); 062 e.um = new UIManager(); 063 e.tm = new ToolsManager(); 064 065 e.autoDataFilename = null; 066 e.currentDataFilename = "nothing loaded yet.."; 067 068 e.dsm.init(); 069 e.vm.init(); 070 e.um.init(); 071 SceneSetting.v().readDataFromFile(); 072 } 073 074 public static DataManager getDataManager() { 075 return e.dm; 076 } 077 078 public static VisualizationManager getVisualizationManager() { 079 return e.vm; 080 } 081 082 public static DataSourceManager getDataSourceManager() { 083 return e.dsm; 084 } 085 086 public static UIManager getUIManager() { 087 return e.um; 088 } 089 090 public static ToolsManager getToolsManager() { 091 return e.tm; 092 } 093 094 public static Filter getFilter() { 095 return e.filter; 096 } 097 098 public static JFrame getFrame() { 099 return e.um.getFrame(); 100 } 101 102 public static void setStatus(String status) { 103 e.um.setStatus(status); 104 } 105 106 public static int getColorRGB() { 107 return e.dm.getColorRGB(); 108 } 109 110 public static Color getColor() { 111 return e.dm.getColor(); 112 } 113 114 public static long getEventCounter() { 115 return e.dm.getEventCounter(); 116 } 117 118 public static void loadDataSource() { 119 setStatus("Loading data, please wait."); 120 e.dataLoaded = e.dm.isDataLoaded(); 121 Thread thread = new Thread() { 122 public void run() { 123 try { 124 e.um.disableFileMenus(); 125 e.um.disableFunctionMenus(); 126 e.dm.init(); 127 e.um.init(); 128 e.vm.init(); 129 setStatus("Data loaded."); 130 e.dm.setDataLoaded(true); 131 e.um.updateDatasourceCombo(); 132 e.um.enableFileMenus(); 133 e.um.enableMenu(); 134 } catch (CancelLoadDataException exp) { 135 e.dm.setDataLoaded(e.dataLoaded); 136 if (e.dataLoaded) { 137 e.um.updateDatasourceCombo(); 138 e.um.enableMenu(); 139 } 140 e.um.enableFileMenus(); 141 } catch (DataProcessingException exp) { 142 e.dm.setDataLoaded(false); 143 e.um.enableFileMenus(); 144 setStatus(exp.getMessage()); 145 } catch (EVolveException exp) { 146 e.dm.setDataLoaded(false); 147 setStatus(exp.getMessage());//"Invalid data format!"); 148 e.um.enableFileMenus(); 149 } 150 } 151 }; 152 thread.start(); 153 } 154 155 public static void autoLoadDataSource() { 156 setStatus("Loading data, please wait."); 157 e.filter = new Filter(); 158 try { 159 e.um.disableFileMenus(); 160 e.vm.init(); 161 e.um.init(); 162 e.dm.init(); 163 setStatus("Data loaded."); 164 e.dm.setDataLoaded(true); 165 e.um.updateDatasourceCombo(); 166 e.um.enableFileMenus(); 167 e.um.enableMenu(); 168 } catch (DataProcessingException exp) { 169 e.um.enableFileMenus(); 170 e.dm.setDataLoaded(false); 171 setStatus(exp.getMessage()); 172 } catch (Exception e) {} 173 } 174 175 public static void visualize() { 176 setStatus("Processing data, please wait."); 177 178 ProcessingThread thread = new ProcessingThread(); 179 ProgressIndicator progress = new ProgressIndicator(getFrame(),e.dm, thread); 180 181 thread.start(); 182 } 183 184 public static void autoVisualize() { 185 setStatus("Processing data, please wait."); 186 187 try { 188 e.dm.sendEvents(); 189 e.vm.visualize(); 190 setStatus("Visualization finished."); 191 } catch (DataProcessingException e) { 192 setStatus(e.getMessage()); 193 } 194 } 195 196 public static String getDataFileName() { 197 return e.autoDataFilename; 198 } 199 200 public static void setDataFilename(String filename) { 201 e.autoDataFilename = filename; 202 if (filename!=null) e.currentDataFilename = filename; 203 } 204 205 public static void clearFilters() { 206 e.filter = new Filter(); 207 } 208 209 public static void showErrorMessage(String msg) { 210 JOptionPane.showMessageDialog(e.um.getDesktop(),msg,"Error Message",JOptionPane.ERROR_MESSAGE); 211 } 212 213 public static void setCurrentDataFilename(String filename) { 214 e.currentDataFilename = filename; 215 } 216 217 public static String getCurrentDataFilename() { 218 return e.currentDataFilename; 219 } 220 221 public static void selectDataSource(DataManager dm, Filter filter) { 222 e.dm = dm; 223 e.filter = filter; 224 } 225 226 public static URL getGifURL(String filename) { 227 return e.getClass().getResource("img/"+filename); 228 } 229 }